package suncertify.application;

import suncertify.application.exceptions.DatabaseFileNotFoundException;
import suncertify.application.exceptions.DatabaseFileNotReadableException;
import suncertify.application.exceptions.DatabaseFileNotWritableException;
import suncertify.application.exceptions.DatabaseFileWrongTypeException;
import suncertify.application.exceptions.ServerStartException;
import suncertify.application.exceptions.ServerStopException;
import suncertify.gui.ServerApplicationFrame;

/**
 * This interface represents the controller and view of the {@link ServerApplicationFrame} frame. This interface
 * represents a simplified version of the Model View Controller pattern, where the controller and view can be
 * implemented by one class. This interface makes the {@link ServerApplicationFrame} independent of a specific class or
 * classes.
 * 
 * @see ServerApplicationFrame
 * 
 */
public interface ServerApplicationFrameInterface {

    /**
     * Definition for a method that returns the application's database file path.
     * 
     * @return Database file path.
     */
    public String getDatabaseFilePath();

    /**
     * Definition for a method that terminates the application.
     */
    public void terminateApplication();

    /**
     * Definition for a method that stops the server. Stopped server means that client applications cannot connect to
     * it.
     * 
     * @throws ServerStopException
     *             Implementors show throw this exception if the server fails to stop.
     */
    public void stopServer() throws ServerStopException;

    /**
     * Definition for a method that start the server. A started server accepts connections for client applications.
     * 
     * @param filePath
     *            Path to the applications database file on the local computer.
     * @param port
     *            The port number on which the server accepts client requests.
     * 
     * @throws ServerStartException
     *             Implementors should throw this exception when the server fails to start.
     */
    public void startServer(String filePath, int port) throws ServerStartException;

    /**
     * A definition for a method that validates the application's database file.
     * 
     * @param databaseFilePath
     *            Path to the database file.
     * @return True if the database file is found in the file system, has the correct extension, is readable and
     *         writable, otherwise false.
     * @throws DatabaseFileNotFoundException
     *             Thrown if the file is not found.
     * @throws DatabaseFileWrongTypeException
     *             Thrown if the file has the wrong extension.
     * @throws DatabaseFileNotReadableException
     *             Thrown if the file is not readable.
     * @throws DatabaseFileNotWritableException
     *             Thrown if the file is not writable.
     */
    public boolean isDatabaseFileValid(String databaseFilePath) throws DatabaseFileNotFoundException,
	    DatabaseFileWrongTypeException, DatabaseFileNotReadableException, DatabaseFileNotWritableException;

    /**
     * Definition for a method that validates the TCP port number.
     * 
     * @param portNumber
     *            The port number to be validated.
     * @return True if the port number is valid, false otherwise.
     */
    public boolean isPortNumberValid(int portNumber);

    /**
     * Method that returns the port number to the caller.
     * 
     * @return The port number.
     */
    public int getPortNumber();

    /**
     * Definition for a method that returns the applications user current directory.
     * 
     * @return Directory path of the current user running the application.
     */
    public String getUserCurrentDirectory();
}
